package src.Thirteen;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JTextFieldTest extends JFrame {

    public JTextFieldTest(){
        final JTextField jt = new JTextField("aaaa",20);
        final JButton jb = new JButton("清除");
        jt.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jt.setText("触发事件");
            }
        });
        jb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jt.setText("");
                jt.requestFocus();
            }
        });

        JPanel jPanel = new JPanel();
        jPanel.add(jb);
        jPanel.add(jt);

        //Container container = getContentPane();
        JTextArea jTextArea = new JTextArea("文本域",6,6);
        jTextArea.setLineWrap(true);
        //container.add(jTextArea);
        jPanel.add(jTextArea);

        this.add(jPanel);
        this.setSize(500,500);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        JTextFieldTest jTextFieldTest = new JTextFieldTest();
    }
}
